package gugga.logging.publishers
{
	import gugga.logging.LogRecord;
	import gugga.logging.IFilter;
	import gugga.logging.Level;
	import gugga.logging.IFormatter;
	import gugga.logging.IPublisher;

	public class BasePublisher implements IPublisher
	{
		private var filter:IFilter;
		private var formatter:IFormatter;
		private var level:Level;
		
		public function publish(logRecord:LogRecord):void
		{
			//implement in child classes
		}
		
		/**
		*	@see gugga.logging.IPublisher
		*/
		public function setFilter(filter:IFilter):void
		{
			this.filter = filter;
		}
		
		/**
		*	@see gugga.logging.IPublisher
		*/
		public function getFilter():IFilter
		{
			return this.filter;
		}
		
		/**
		*	@see gugga.logging.IPublisher
		*/
		public function setFormatter(formatter:IFormatter):void
		{
			this.formatter = formatter;
		}
	
		/**
		*	@see gugga.logging.IPublisher
		*/	
		public function getFormatter():IFormatter
		{
			return this.formatter;
		}
		
		/**
		*	@see gugga.logging.IPublisher
		*/
		public function setLevel(level:Level):void
		{
			this.level = level;
		}
		
		/**
		*	@see gugga.logging.IPublisher
		*/
		public function getLevel():Level
		{
			return this.level;
		}
		
		/**
		*	@see gugga.logging.IPublisher
		*/
		public function isLoggable(logRecord:LogRecord):Boolean
		{
			if (this.getLevel() > logRecord.getLevel()) {
				return false;
			}
			
			if (this.getFilter() == null) {
				return true;
			}
			
			if (this.getFilter().isLoggable(logRecord)) {
				return true;
			}
			
			return false;
		}
	}
}